package com.ruoyi.web.controller.wnjk.app.shop;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.wnjk.domain.po.ShopSubject;
import com.ruoyi.system.wnjk.service.IShopSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/app/shop/subject")
public class AppShopSubjectController extends BaseController {

    @Autowired
    private IShopSubjectService shopSubjectService;

    /**
     * 查询分类列表
     */
//    @PreAuthorize("@ss.hasPermi('system:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopSubject shopSubject)
    {
        startPage();
        List<ShopSubject> list = shopSubjectService.selectShopSubjectList(shopSubject);
        return getDataTable(list);
    }

    /**
     * 导出分类列表
     */
//    @PreAuthorize("@ss.hasPermi('system:subject:export')")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopSubject shopSubject)
    {
        List<ShopSubject> list = shopSubjectService.selectShopSubjectList(shopSubject);
        ExcelUtil<ShopSubject> util = new ExcelUtil<ShopSubject>(ShopSubject.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopSubjectService.selectShopSubjectById(id));
    }

    /**
     * 新增分类
     */
//    @PreAuthorize("@ss.hasPermi('system:subject:add')")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopSubject shopSubject)
    {
        return toAjax(shopSubjectService.insertShopSubject(shopSubject));
    }

    /**
     * 修改分类
     */
//    @PreAuthorize("@ss.hasPermi('system:subject:edit')")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopSubject shopSubject)
    {
        return toAjax(shopSubjectService.updateShopSubject(shopSubject));
    }

    /**
     * 删除分类
     */
//    @PreAuthorize("@ss.hasPermi('system:subject:remove')")
    @Log(title = "分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopSubjectService.deleteShopSubjectByIds(ids));
    }
}
